package com.lsp.test;

import com.lsp.annotation.Autowired;
import com.lsp.annotation.Controller;
import com.lsp.annotation.RequestMapping;
import com.lsp.bean.Model;
import com.lsp.eunm.RequestMethod;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    private IUser UserService;

    @RequestMapping(value = "/userList", method = RequestMethod.GET)
    public Model getUserList(){
        List<User> userList = UserService.getAllUser();
        return new Model(userList);
    }

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public Model hello(User user){
        return new Model("你好！"+user);
    }

    @RequestMapping(value = "/userEdit", method = RequestMethod.GET)
    public Model editUser(User user){
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("USER_NAME", user.getUsername());
        boolean updateUser = UserService.updateUser(user.getId(), fieldMap);
        return  updateUser ? new Model("修改成功") :  new Model("修改失败！");
    }
}
